import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_signaturepad/signaturepad.dart';
import 'package:xsdk_flutter/xsdk/framework/base/xsdk_function.dart';
import 'package:xsdk_flutter/xsdk/utils/x_utils_widget.dart';


/*
签名板
https://help.syncfusion.com/flutter/signaturepad/getting-started

dependencies:
  syncfusion_flutter_signaturepad: ^22.1.39
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';


 */
abstract class XSignaturePadUtils{

  /*
  通过key获得当前签名图片
  GlobalKey<SfSignaturePadState> _signaturePadKey = GlobalKey();

  获得签名图片: ui.Image image = await _signaturePadKey.currentState!.toImage();
  清除当前签名: ui.Image image = _signaturePadKey.currentState!.clear();

   */

  static Widget getWidgetSignaturePad(
      {
        Key? key, //可通过key获得当前签名图片
        double? width,
        double? height,
        Color backgroundColor=Colors.white,
        Color color=Colors.black,
        XFunctionResultCallback? callback
      }
      ){
    return XWidgetUtils.getLayoutContainer(
        width: width,
        height: height,
        backgroundColor: backgroundColor,
        child: SfSignaturePad(
          key: key,
          strokeColor: color,
          minimumStrokeWidth: 1.0,
          maximumStrokeWidth: 5.0,
          // onDrawStart: () {
          //   return false;
          // },
          // onDraw: (offset, time) {
          //   Offset offsetValue = offset;
          //   DateTime dateTime = time;
          // },
          onDrawEnd: () {
            //print("Signature has been completed in Signature Pad");
            if(callback!=null){
              //通知签名有内容(已签名)
              callback(true);
            }
          },
        )
    );
  }





}
